package com.dhcc.sds.standard.service.impl;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.dhcc.core.framework.result.node.ZTreeNode;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.sds.standard.dao.SdsStandSourceMapper;
import com.dhcc.sds.standard.service.ISdsStandSourceService;
import com.dhcc.sds.standard.entity.SdsStandSourceEntity;

/**
 * 数据源定义表数据服务层接口
 * 
 * @ClassName: SdsStandSourceServiceImpl
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:09:52
 */
@Service("sdsStandSourceService")
public class SdsStandSourceServiceImpl extends BaseServiceImpl<SdsStandSourceMapper, SdsStandSourceEntity> implements ISdsStandSourceService {

	@Autowired
	private SdsStandSourceMapper sourceMapper;

	@Override
	public List<SdsStandSourceEntity> page(Page<SdsStandSourceEntity> page, Map<String, Object> map) {
		return this.baseMapper.page(page, map);
	}
	@Override
	public List<SdsStandSourceEntity> list(Map<String, Object> map) {
		return this.baseMapper.list(map);
	}

	@Override
	public JSONObject getSourceMap() {
		List<SdsStandSourceEntity> list = sourceMapper.selectList(null);
		JSONObject sourceMap = new JSONObject();
		sourceMap.put("", "");
		for(SdsStandSourceEntity sourceEntity : list){
			sourceMap.put(String.valueOf(sourceEntity.getId()), sourceEntity.getSourceDesc());
		}
		return sourceMap;
	}

	@Override
	public SdsStandSourceEntity getSourceByDesc(String desc) {

		SdsStandSourceEntity sourceEntity = new SdsStandSourceEntity();
		sourceEntity.setSourceDesc(desc);
		SdsStandSourceEntity sourceEntity1 = sourceMapper.selectOne(sourceEntity);
		return sourceEntity1;
	}

	@Override
	public List<ZTreeNode> getEntityTree() {
		List<ZTreeNode> tree = this.baseMapper.tree();
		tree.add(ZTreeNode.createRoot("数据源"));
		return tree;
	}

	@Override
	public String getSourceNameByDic(Long id) {
		return sourceMapper.selectSourceNameByDic(id);
	}

	@Override
	public String getSourceNameByDicSub(Long id) {
		return sourceMapper.selectSourceNameByDicSub(id);
	}

	@Override
	public JSONArray getSourceArrayMap() {
		List<SdsStandSourceEntity> sdsStandSourceEntities = this.baseMapper.selectList(null);
		JSONArray officeArry = new JSONArray();
		for(SdsStandSourceEntity sourceEntity : sdsStandSourceEntities){
			JSONObject officeObj = new JSONObject();
			officeObj.put("value", sourceEntity.getId() + "");
			officeObj.put("text", sourceEntity.getSourceDesc());
			officeArry.add(officeObj);
		}
		return officeArry;
	}

}